package com.czr.service.collect;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.czr.entity.Collect;
import com.czr.entity.CollectCategory;
import com.czr.mapper.CollectMapper;
import com.czr.service.collectcategory.CollectCategoryService;
import com.czr.vo.CollectVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * Description:
 * Author: czr
 * Version: 1.0
 * Create Date Time: 2021/12/22 17:11.
 */
@Service
@Slf4j
public class CollectDbServiceImpl extends ServiceImpl<CollectMapper, Collect> implements CollectService {

    @Autowired
    private CollectCategoryService collectCategoryService;

    @Override
    public List<CollectVo> findList() {
        log.info("--->CollectDbServiceImpl");

        // 1: 查询分类数据
        List<CollectCategory> collectCategorylist = collectCategoryService.list();

        List<CollectVo> collectVoList = new ArrayList<>();
        for (CollectCategory collectCategory : collectCategorylist) {
            CollectVo collectVo = new CollectVo();
            LambdaQueryWrapper<Collect> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(Collect::getCategoryId, collectCategory.getId());
            queryWrapper.eq(Collect::getStatus, 1);

            List<Collect> collectlist = this.list(queryWrapper);
            collectVo.setCategoryId(collectCategory.getId());
            collectVo.setCategoryTitle(collectCategory.getCategoryTitle());
            collectVo.setCollectList(collectlist);

            collectVoList.add(collectVo);
        }


        return collectVoList;
    }

}
